package nyist.media.vo;

import cn.hutool.core.date.DatePattern;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import nyist.media.entity.RepairRecord;
import nyist.media.enums.RepairStatus;

import java.util.Date;

/**
 * @author dcf
 * @date 2019/3/17
 */
@Data
public class RepairRecordVO {

    /**
     * 维修单ID
     */
    private Long id;

    /**
     * 提交人
     */
    private String applyName;


    /**
     * 维修人
     */
    private String repairName;

    /**
     * 维修单内容
     */
    private String text;

    /**
     * 维修单状态
     */
    private String status;

    /**
     * 驳回理由
     */
    private String rejectedReason;

    /**
     * 维修时间
     */
    @JSONField(format = DatePattern.NORM_DATETIME_MINUTE_PATTERN)
    private Date repairDaTe;

    /**
     * 维修完成时间
     */
    @JSONField(format = DatePattern.NORM_DATETIME_MINUTE_PATTERN)
    private Date commitDate;

    public RepairRecordVO(RepairRecord repairRecord) {
        this.applyName = repairRecord.getCommitAdmin().getName();
        this.repairName = repairRecord.getRepairAdmin() == null ? "" : repairRecord.getRepairAdmin().getName();
        this.id = repairRecord.getId();
        this.repairDaTe = repairRecord.getRepairDate();
        this.commitDate = repairRecord.getCommitDate();
        this.rejectedReason = repairRecord.getRejectedReason();
        this.text = repairRecord.getText();
        if (repairRecord.getStatus().equals(RepairStatus.REJECTED)) {
            this.status = "驳回";
        } else if (repairRecord.getStatus().equals(RepairStatus.REPAIRED)) {
            this.status = "已维修";
        } else if (repairRecord.getStatus().equals(RepairStatus.REPAIRING)) {
            this.status = "维修中";
        }  else {
            this.status = "待维修";
        }
    }

}
